%% treedumper.erl
%%      A dummy parse transformation, that prints the abstract syntax tree of a mdoule,
%%      and dumps its source code to a file.
%% 
%% Copyright (C) 2008, 2009 Gábor Fehér
%%
%% This file is part of ECT.
%% 
%% ECT is free software: you can redistribute it and/or modify
%% it under the terms of the GNU General Public License as published by
%% the Free Software Foundation, either version 3 of the License, or
%% (at your option) any later version.
%% 
%% ECT is distributed in the hope that it will be useful,
%% but WITHOUT ANY WARRANTY; without even the implied warranty of
%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
%% GNU General Public License for more details.
%% 
%% You should have received a copy of the GNU General Public License
%% along with ECT.  If not, see <http://www.gnu.org/licenses/>.
%%
-module(treedumper).
-export([parse_transform/2]).

%% Function: parse_transform(Forms, Options)
%% Purpose: entry point for the parse transformation:
%% Arguments:
%%   Forms: the AST forms of the module to parse-transform
%%   Options: compiler options - ignored
%% Side-effects:
%%   Forms are dumped to the screen
%%   the source code represented by Forms is dumped to a file named treedumper.out
%% Returns:
%%   Forms - thus, this is an identity transformation
parse_transform(Tree, _) ->
    io:format("TREE: ~p~nSOURCE: ~n", [Tree]),
    my_pp:print(Tree, "treedumper.out", false),
    Tree.
